package com.sysmanage.permissions.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sysmanage.common.tools.util.ArgumentMemoryUtils;
import com.sysmanage.framework.dao.hspring.DAOInterface;
import com.sysmanage.framework.service.BaseService;
import com.sysmanage.permissions.ConstCode;
import com.sysmanage.permissions.dao.GroupDao;
import com.sysmanage.permissions.model.Groups;
import com.sysmanage.permissions.model.Role;
import com.sysmanage.permissions.service.IGroupService;

@Service
@Transactional
public class GroupService extends BaseService<Groups> implements IGroupService {
	@Autowired
	private GroupDao groupDao;
	
	public List<Groups> getAll() {
		return groupDao.getAll();
	}

	@Override
	protected DAOInterface<Groups> getDAO() {
		return groupDao;
	}

	public void addUserToGroup(String userIds,String groupId) {
		groupDao.addUserToGroup(userIds,groupId);
	}

	public void delUserFromGroup(String groupId, String userIds) {
		groupDao.delUserFromGroup(groupId, userIds);
		
	}
	public List<Role> otherRoleFromGroup(String groupId) {
		return groupDao.otherRoleFromGroup(groupId);
	}
	
	
	public List<Role> groupHaveRole(String groupid) {
		return this.groupDao.groupHaveRole(groupid);
	}
	public void addRoleToGroup(String roleIds, String groupId) {
		this.groupDao.addRoleToGroup(roleIds, groupId);		
	}

	public void delGroupHaveRole(String id, String roleIds) {
		this.groupDao.removeGroupHaveRole(id, roleIds);
		
	}	
	public List<Map<String,Object>> getTree(String id) {
		return this.groupDao.getTree(id);
	}
	public boolean deleteGroupById(Integer id)
	{
		boolean ret = true;	
		//先删除所有的子组
		ret = groupDao.deleteById(id);
		return ret;
	}
	public boolean saveGroup(Groups group)
	{
		boolean ret = true;		
		ret =  this.groupDao.save(group);
		return ret;
	}
	/* (non-Javadoc)
	 * <p>Title: getGroups</p> 
	 * <p>Description: </p> 
	 * @param nameGroup
	 * @return 
	 * @see com.sysmanage.permissions.biz.IGroupService#getGroups(java.lang.String) 
	 */
	
	@Override
	public List<Groups> getGroups(String nameGroup) {
		return groupDao.getGroups(nameGroup);
	}
	/** 
	  * @Title: getSubGroups 
	  * @Description: 根据组ID找子组
	  * @param @param groupId
	  * @param @return
	  * @return List<Groups>
	  * @throws 
	  */
	public List<Groups> getSubGroups(Integer groupId){
		return groupDao.getSubGroups(groupId);
	}
}
